home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
11255
/
11255.xpi
/
chrome
/
content
/
controller
/
WindowManager.js
< prev
Wrap
Text File
|
2009-11-25
|
10KB
|
295 lines
/* ***** BEGIN LICENSE BLOCK *****
*
* Pearltrees add-on AMO, Copyright(C), 2009, Broceliand SAS, Paris, France
* (company in charge of developing Pearltrees)
*
* This file is part of ΓÇ£Pearltrees add-on AMOΓÇ¥.
*
* Pearltrees add-on AMO is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License version 3 as published by the Free Software Foundation.
*
* Pearltrees add-on AMO is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Pearltrees add-on AMO.
* If not, see <http://www.gnu.org/licenses/>
*
* ***** END LICENSE BLOCK ***** */
/////////////////////////////////////////////////////////////////////////////////
// Windows manager
/////////////////////////////////////////////////////////////////////////////////
const BRO_WINDOW_STORAGE_MODE_FUEL = 1; // Firefox 3+
const BRO_WINDOW_STORAGE_MODE_HACK = 2; // Firefox 2-
var BRO_windowManager = {
_storage:null,
_storageMode:null, //1='FUEL' or 2='HACK'
init: function() {
var hiddenWindow = Components.classes["@mozilla.org/appshell/appShellService;1"]
.getService(Components.interfaces.nsIAppShellService)
.hiddenDOMWindow;
// Firefox 3 use FUEL storage
if(typeof(Application) != 'undefined' && Application.storage) {
BRO_windowManager._storage = Application.storage;
BRO_windowManager._storageMode = BRO_WINDOW_STORAGE_MODE_FUEL;
}
// Firefox 2 use hidden window hack
else if(hiddenWindow) {
hiddenWindow.setBroData = function(name, value){
this[name] = value;
}
hiddenWindow.getBroData = function(name, defaultValue){
return (this[name])?this[name]:defaultValue;
}
BRO_windowManager._storage = hiddenWindow;
BRO_windowManager._storageMode = BRO_WINDOW_STORAGE_MODE_HACK;
}else {
BRO_log.error("Can't find a storage manager.\n We won't be able to syncronize state between windows");
}
},
/**
* Synchronize this window with the datas stored globaly.
*/
synchronize: function() {
if(!BRO_toolbar.isInit) return;
if(BRO_model.getCurrentUser() != BRO_windowManager.getCurrentUser()) {
BRO_model.setCurrentUser(BRO_windowManager.getCurrentUser());
}
var treeListsEquals = BRO_model.areTreeListsEquals(BRO_model.getTreeList(), BRO_windowManager.getTreeList());
var historyListsEquals = BRO_model.areHistoryListsEquals(BRO_model.getHistoryList(), BRO_windowManager.getHistoryList());
if(!treeListsEquals || !historyListsEquals) {
BRO_model.setTreeList(BRO_windowManager.getTreeList());
BRO_model.setHistoryList(BRO_windowManager.getHistoryList());
BRO_inButtonController.rebuildTreeListAndBackupSelection();
}
if(BRO_inButtonController.getSelectedTree() != BRO_windowManager.getSelectedTree()
|| BRO_inButtonController.getSelectedHistory() != BRO_windowManager.getSelectedHistory()
|| BRO_inButtonController.getSelectedNewHistory() != BRO_windowManager.getSelectedNewHistory()) {
if(BRO_windowManager.getSelectedTree()) {
BRO_inButtonController.selectTree(BRO_windowManager.getSelectedTree().treeID);
}
else if(BRO_windowManager.getSelectedHistory()) {
BRO_inButtonController.selectHistory(BRO_windowManager.getSelectedHistory().id);
}
else if(BRO_windowManager.getSelectedNewHistory()) {
BRO_inButtonController.selectNewHistory(BRO_windowManager.getSelectedNewHistory());
}
}
if(BRO_toolbar.isRecording == false && BRO_windowManager.isRecording()) {
if(BRO_windowManager.isNewWindow()) {
BRO_actionListener.setLastAction(BRO_METHOD_NEW_WINDOW);
BRO_windowManager.setWindowOpenerID(null);
}
BRO_toolbar.setRecording(true);
}else if(BRO_toolbar.isRecording == true && !BRO_windowManager.isRecording()){
BRO_toolbar.setRecording(false);
}
if(BRO_windowManager.getRecordingMode() && BRO_toolbar.getRecordingMode() != BRO_windowManager.getRecordingMode()) {
BRO_toolbar.setRecordingMode(BRO_windowManager.getRecordingMode());
}
},
isNewWindow:function(){
return (BRO_windowManager.getWindowOpenerID())?true:false;
},
/**
* This is the BrowserID of the the new window opener.
* @param string browserID
*/
setWindowOpenerID:function(browserID) {
BRO_windowManager.setData('windowOpenerID',browserID);
},
/**
* Return the BrowserID of the opener.
* @return string browserID
*/
getWindowOpenerID:function() {
return BRO_windowManager.getData('windowOpenerID',null);
},
/**
* @param boolean isRecording
*/
setRecording:function(isRecording){
BRO_windowManager.setData('isRecording',isRecording);
},
/**
* @return boolean isRecording
*/
isRecording:function(){
return BRO_windowManager.getData('isRecording',false);
},
/**
* @param integer value
*/
setRecordingMode:function(value) {
BRO_windowManager.setData('recordingMode',value);
},
/**
* @return integer
*/
getRecordingMode:function() {
return BRO_windowManager.getData('recordingMode',0);
},
/**
* user treeList
* @param array treeList
*/
setTreeList:function(treeList) {
BRO_windowManager.setData('treeList',treeList);
},
/**
* user treeList
* @return array treeList
*/
getTreeList:function() {
return BRO_windowManager.getData('treeList',null);
},
/**
* user historyList
* @param array historyList
*/
setHistoryList:function(historyList) {
BRO_windowManager.setData('historyList',historyList);
},
/**
* user historyList
* @return array historyList
*/
getHistoryList:function() {
return BRO_windowManager.getData('historyList',null);
},
/**
* current user
* @param currentUser
*/
setCurrentUser:function(currentUser) {
BRO_windowManager.setData('currentUser',currentUser);
},
/**
* currentUser
* @return currentUser
*/
getCurrentUser:function() {
return BRO_windowManager.getData('currentUser',null);
},
/**
* selected tree in the list
* @param object selectedTree
*/
setSelectedTree:function(selectedTree) {
BRO_windowManager.setData('selectedTree',selectedTree);
},
/**
* selected tree in the list
* @return object
*/
getSelectedTree:function() {
return BRO_windowManager.getData('selectedTree',null);
},
/**
* selected history in the list
* @param object selectedHistory
*/
setSelectedHistory:function(selectedHistory) {
BRO_windowManager.setData('selectedHistory', selectedHistory);
},
/**
* selected history in the list
* @return object
*/
getSelectedHistory:function() {
return BRO_windowManager.getData('selectedHistory',null);
},
/**
* newHistory
* @param string newHistory
*/
setSelectedNewHistory:function(newHistory) {
BRO_windowManager.setData('newHistory', newHistory);
},
/**
* newHistory
* @return string
*/
getSelectedNewHistory:function() {
return BRO_windowManager.getData('newHistory',null);
},
/**
* Set data in the storage
* @param string name
* @param object value
*/
setData:function(name, value) {
if(BRO_windowManager._storageMode == BRO_WINDOW_STORAGE_MODE_FUEL) {
BRO_windowManager._storage.set(name, value);
}else if(BRO_windowManager._storageMode == BRO_WINDOW_STORAGE_MODE_HACK){
BRO_windowManager._storage.setBroData(name, value);
}
},
/**
* Get data from the storage
* @param string name
* @param object defaultValue
* @return object
*/
getData:function(name, defaultValue) {
if(BRO_windowManager._storageMode == BRO_WINDOW_STORAGE_MODE_FUEL) {
return BRO_windowManager._storage.get(name, defaultValue);
}else if(BRO_windowManager._storageMode == BRO_WINDOW_STORAGE_MODE_HACK){
return BRO_windowManager._storage.getBroData(name, defaultValue);
}
},
/**
* Count the number of windows opened.
* @return integer
*/
countWindows:function(){
if(typeof(Application) != 'undefined' && Application.windows) {
return Application.windows.length;
}else{
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var enumerator = wm.getEnumerator('navigator:browser');
for(var i=0; enumerator.hasMoreElements(); i++) {
// Fix bug on reloading FF2 through chrome extension
// nsISimpleEnumerator does not seem stable
// TODO find a better way to do this
if(i>50) {
break;
}
}
return i;
}
}
}